//
//  FZComposeTollBarView.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/26/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit

enum FZComposeToolBarType: Int {
    case Picture = 0
    case Mention = 1
    case Trend = 2
    case Emoticon = 3
    case Add = 4
}

class FZComposeToolBarView: UIView {

    var callBack: ((type: FZComposeToolBarType)->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        self.backgroundColor = ThemColor
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupUI() {
        
        let pictureButton = getButton("compose_toolbar_picture")
        let mentionButton = getButton("compose_mentionbutton_background")
        let trendButton = getButton("compose_trendbutton_background")
        let emoticonButton = getButton("compose_emoticonbutton_background")
        let addButton = getButton("compose_add_background")
        
        pictureButton.snp_makeConstraints { (make) in
            
            make.top.leading.bottom.equalTo(0)
            
        }
        mentionButton.snp_makeConstraints { (make) in
            make.top.equalTo(0)
            make.leading.equalTo(pictureButton.snp_trailing)
            
            make.size.equalTo(pictureButton)
        }
        trendButton.snp_makeConstraints { (make) in
            make.top.equalTo(0)
            make.leading.equalTo(mentionButton.snp_trailing)
            
            make.size.equalTo(pictureButton)
        }
        emoticonButton.snp_makeConstraints { (make) in
            make.top.equalTo(0)
            make.leading.equalTo(trendButton.snp_trailing)
            make.size.equalTo(pictureButton)
        }
        addButton.snp_makeConstraints { (make) in
            make.top.trailing.equalTo(0)
            make.leading.equalTo(emoticonButton.snp_trailing)
            make.size.equalTo(pictureButton)
        }
    }
//MARK:==========================时间==========================
  @objc private func clickToolButton(sender: UIButton) {
        
        let index: Int = self.subviews.indexOf(sender)!
        callBack?(type: FZComposeToolBarType(rawValue: index)!)
    }
//MARK:==========================属性==========================
    func getButton(imageNamed: String) -> UIButton{
        
        let btn : UIButton = UIButton()
        btn.addTarget(self, action: #selector(clickToolButton(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        btn.setImage(UIImage(named: imageNamed), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "\(imageNamed)_highlighted"), forState: UIControlState.Highlighted)
            
        btn.setBackgroundImage(UIImage(named: "compose_toolbar_background"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "compose_toolbar_background"), forState: UIControlState.Highlighted)
        addSubview(btn)
        return btn
    }

}
